/*
    Nios-sim - one simple NIOSII simulator only for personal interest and fun.
    Copyright (C) 2010  chysun2000@gmail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#ifndef __IO_DEVICE_H__
#define __IO_DEVICE_H__
#include <stdio.h>

#define ADDR_IS_NOT_DEV (0)
#define ADDR_IS_DEV (1)

#define DEV_HAS_IRQ (1)
#define DEV_NO_IRQ  (0)

struct io_device;
struct io_device {
	void * priv_data;
	char * name;
	uint32_t irq_enable_mask;
	void (*init)(struct io_device * self);
	int32_t (*is_belong)(uint32_t address);
	uint32_t (*read_data)(struct io_device * self, uint32_t addr, uint32_t data_len);
	void (*write_data)(struct io_device * self, uint32_t addr, uint32_t data, uint32_t data_len);
	int32_t (*has_irq)(struct io_device * self);
	void (*simulate)(struct io_device * self);
	
};

struct io_reg {
	uint32_t addr;
	uint32_t value;
	uint32_t valid_mask;
	uint32_t only_read_mask;
};

extern void init_devices(void);
extern struct io_device * get_device(uint32_t address);

extern uint32_t io_write_data(uint32_t old_data, uint32_t new_data, uint32_t data_len);
extern uint32_t io_read_data(uint32_t old_data, uint32_t data_len);
extern uint32_t io_write_data_mask(uint32_t old_data, uint32_t new_data, uint32_t data_len, 
										uint32_t valid_mask, uint32_t only_read_mask);
extern void hw_simulating(void);
extern uint32_t get_io_irq_status(void);

extern uint32_t check_reg_bit(uint32_t value, uint32_t mask);
#endif


